package com.cn.springcloudwechat.controller.vaccinestation;


import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.mybatis.Page;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.controller.vaccine.log.LogInfo;
import com.cn.springcloudwechat.controller.vaccine.log.OperateType;
import com.cn.springcloudwechat.model.dto.AreaDto;
import com.cn.springcloudwechat.model.vaccinestion.YmStationWorkVOrder;
import com.cn.springcloudwechat.model.vaccinestion.YmStationWorkVTime;
import com.cn.springcloudwechat.model.vaccinestion.YmVStation;
import com.cn.springcloudwechat.service.personalcenter.service.AreaService;
import com.cn.springcloudwechat.service.vaccinstation.VaccineStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("/vaccinestation")
public class VaccineStationVController {
	
	@Autowired
	VaccineStationService vaccineStationService;

	@Autowired
	AreaService areaService;

	/**
	 * 疫苗站新增
	 * @param ajaxRes
	 * @param ymVStation
	 * @param YmStationWorkVTime
	 * @return
	 */
	@RequestMapping("/insertVaccineStation")
	public AjaxRes insertVaccineStation(AjaxRes ajaxRes, YmVStation ymVStation, YmStationWorkVTime YmStationWorkVTime){
		try {
        	this.vaccineStationService.insertVaccineStationSer(ymVStation, YmStationWorkVTime);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}
	
	/**
	 * 疫苗站修改
	 * @param ajaxRes
	 * @param ymVStation
	 * @param YmStationWorkVTime
	 * @return
	 */
	@RequestMapping("/updateVaccineStation")
	public AjaxRes updateVaccineStation(AjaxRes ajaxRes, YmVStation ymVStation, YmStationWorkVTime YmStationWorkVTime){
		try {
        	this.vaccineStationService.updateVaccineStationSer(ymVStation, YmStationWorkVTime);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}

	/**
	 * 疫苗站查询
	 * @param ajaxRes
	 * @param ymVStation
	 * @param page
	 * @return
	 */
	@RequestMapping("/queryVaccineStation")
	public AjaxRes queryVaccineStation(AjaxRes ajaxRes, YmVStation ymVStation, Page<YmVStation> page){
		try {
			Page<YmVStation> ymVStationPage = this.vaccineStationService.queryVaccineStationSer(ymVStation,page);
            ajaxRes.setSucceed(ymVStationPage,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}


	/**
	 * 新增疫苗站疫苗详情的新增(包括时间段和对应的疫苗)
	 * @param ajaxRes
	 * @param ymStationWorkVOrder
	 * @param parameter
	 * @return
	 */
	@RequestMapping("/insertVaccineStationDetail")
	public AjaxRes insertVaccineStationDetail(AjaxRes ajaxRes, YmStationWorkVOrder ymStationWorkVOrder, String[] parameter){
		try {
			this.vaccineStationService.insertVaccineStationDetailSer(ymStationWorkVOrder,parameter);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}

	/**
	 * 查询某一个疫苗站疫苗(包括时间段和对应的疫苗)
	 * @param ajaxRes
	 * @param ymVStation
	 * @return
	 */
	@RequestMapping("/queryVaccineStationDetail")
	public AjaxRes queryVaccineStationDetail(AjaxRes ajaxRes,YmVStation ymVStation){
		try {
			List<YmVStation> ymVStations = this.vaccineStationService.queryVaccineStationDetailSer(ymVStation);
            ajaxRes.setSucceed(ymVStations,Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}
	
	/**
	 * 查询客户疫苗站
	 * @param ajaxRes
	 * @return
	 */
	/*@RequestMapping("/queryVaccineUser")
	public AjaxRes queryVaccineUser(AjaxRes ajaxRes){
		try {
			List<YmVStation> ymVStations = this.vaccineStationService.queryVaccineUserSer();
            ajaxRes.setSucceed(ymVStations,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
	}*/


	/**
	 * 查询某一个地区的所有疫苗站
	 * @param ajaxRes
	 * @param ymVStation
	 * @return
	 */
	@RequestMapping("/queryVaccineStationByAreaId")
	public AjaxRes queryVaccineStationByAreaId(AjaxRes ajaxRes,YmVStation ymVStation, Page<YmVStation> page){
		try {
			List<YmVStation> ymVStations = this.vaccineStationService.queryVaccineStationByAreaId(ymVStation,page);
			ajaxRes.setSucceed(ymVStations,Const.DATA_SUCCEED);
		}catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询行政区划树
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/queryTree")
	@LogInfo(operateType = OperateType.UPDATE, content = "查询行政区划树")
	public AjaxRes queryTree(AjaxRes ajaxRes){
		List<Map<String,Object>> list = new ArrayList<>();
		Map<String,Object> m = new HashMap<>();
		try {
			List<AreaDto> dictionaryDtoList = this.areaService.queryYmAreaVaStation();
			m.put("children",dictionaryDtoList);
			m.put("id",0);
			m.put("name","全部");
			m.put("perentId",0);
			list.add(m);
			ajaxRes.setSucceed(list, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
